//
//  YXImageScrollView.m
//  YXImageBrowserDemo
//
//  Created by guo peng huang on 2021/5/17.
//

#import "YXImageScrollView.h"

@interface YXImageScrollView ()

@property (nonatomic, strong) YYAnimatedImageView *imageView;

@end

@implementation YXImageScrollView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        self.decelerationRate = UIScrollViewDecelerationRateFast;
        self.maximumZoomScale = 1;
        self.minimumZoomScale = 1;
        self.alwaysBounceHorizontal = NO;
        self.alwaysBounceVertical = NO;
        self.layer.masksToBounds = NO;
        if (@available(iOS 11.0, *)) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }

        [self addSubview:self.imageView];
    }
    return self;
}

- (void)yx_setImage:(__kindof UIImage *)image type:(YXScrollImageType)type {
    self.imageView.image = image;
    self.imageType = type;
}

/** 重置 */
- (void)reset {
    self.zoomScale = 1;
    self.imageView.image = nil;
    self.imageView.frame = CGRectZero;
    self.imageType = YXScrollImageTypeNone;
}

#pragma mark - *_* lazyLoad *_*
- (YYAnimatedImageView *)imageView {
    if (!_imageView) {
        _imageView = [YYAnimatedImageView new];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.layer.masksToBounds = YES;
    }
    return _imageView;
}

@end
